import { PlanItem, PlanType } from "./models";
import req, { RequsetOptons } from "/@/api/req";

export const Api = {
  teamsPage: "civilized/teams/",
  teamCollectorsPage: "civilized/team-collectors/",
  plans: "civilized/plans/",
  template: "civilized/plans/template",
  uploadTemplate: "civilized/plans/uploadTemplate",
};

export function addCollectorsToTeam(data: { teamId: number; tollCollectorIds: number[] }) {
  return req.commonPost(Api.teamCollectorsPage, data);
}

export function getPlan(params: { teamId?: number; startDate: string; endDate: string; pageSize?: number }) {
  params.pageSize = 999;
  return req.commonGet<PlanItem[]>(Api.plans, params, { useGlobalLoading: true });
}

export function setPlan(data: {
  teamId: number;
  planDate: string;
  planType: PlanType;
  tollBoothId: string;
  tollCollectorId: number;
}) {
  return req.commonPost(Api.plans, data);
}

export function updatePlan(data: {
  id: number;
  teamId: number;
  planDate: string;
  planType: PlanType;
  tollBoothId: string;
  tollCollectorId: number;
}) {
  return req.put({
    url: Api.plans,
    data,
  });
}

export function delPlan(planId: number) {
  return req.delete({
    url: Api.plans + "?id=" + planId,
  });
}
